package com.yanwq.sayhi.common.constant;

import android.os.Environment;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * 作者：yanwq。
 * 日期：2016/1/30。
 */
public class CacheConstant {

    private static final String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/SayHi/");
    private static final SimpleDateFormat mFormat = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.CHINA);

    public static String getRootPath() {
        File file = new File(rootPath);
        if (!file.exists()) {
            if (!file.mkdirs()) {
                throw new RuntimeException("应用目录创建异常");
            }
        }

        return rootPath;
    }

    public static String getPath(String dirName) {
        String path = String.format("%s/%s/", getRootPath(), dirName);
        File file = new File(path);
        if (file.exists()) {
            return path;
        }

        if (file.mkdirs()) {
            return path;
        }

        throw new RuntimeException(String.format("%s目录创建异常", dirName));
    }

    public static String getPhotoPath() {
        return getPath("photo");
    }

    public static String getAudioPath() {
        return getPath("audio");
    }

    public static String getVideoPath() {
        return getPath("video");
    }

    public static String getRandomFileName() {
        return mFormat.format(System.currentTimeMillis());
    }
}